/**
 * @file    WebWindow.h
 * @brief   
 * @date    2005-03-15 15:55:23
 * @author  GengYong (gengyong@gmail.com)
 *
 */

#ifndef WEBWINDOW_HEADER_WEBWINDOW_H
#define WEBWINDOW_HEADER_WEBWINDOW_H
//----------------------------------------------------------
#if defined(_WINDLL)
#define WEBWINDOW_EXPORTS
#else
#define WEBWINDOW_IMPORTS
#endif


#if defined(WEBWINDOW_EXPORTS)
#define WEBWINDOWAPI	__declspec(dllexport)
#elif defined(WEBWINDOW_IMPORTS)
#define WEBWINDOWAPI	__declspec(dllimport)
#else 
#define WEBWINDOWAPI
#endif
//----------------------------------------------------------

#include <comdef.h>
#include <mshtml.h>

namespace xessage {
	class IEventHandler
	{
	public:
		virtual ~IEventHandler(){};
		//Fires before navigation occurs in the given object (on either a window or frameset element).
		virtual void BeforeNavigate(IDispatch *pDisp, BSTR url, BSTR TargetFrameName, BSTR Headers, VARIANT_BOOL * Cancel) = 0;
		//Fires to request that the client window size be converted to the host window size.
		virtual void ClientToHostWindow(long *CX, long *CY) = 0;
		//Fires when the enabled state of a command changes.
		virtual void CommandStateChange(long Command, VARIANT_BOOL Enable) = 0;
		//Fires when a document has been completely loaded and initialized.
		virtual void DocumentComplete(IDispatch *pDisp, BSTR URL) = 0;
		//Fires when a navigation operation is beginning.
		virtual void DownloadBegin() = 0;
		//Fires when a navigation operation finishes, is halted, or fails.
		virtual void DownloadComplete() = 0;
		//Fires to indicate that a file download is about to occur.
		//If a file download dialog is to be displayed, 
		//this event is fired prior to the display of the dialog.
		virtual void FileDownload(VARIANT_BOOL * Cancel) = 0;
		//Fires after a navigation to a link is completed on either a window or frameSet element.
		//ref: ms-help://MS.MSDNQTR.2003FEB.2052/progie/workshop/browser/webbrowser/reference/ifaces/dwebbrowserevents2/navigatecomplete2.htm
		virtual void NavigateComplete(IDispatch * pDisp, BSTR URL) = 0;
		//Fires when an error occurs during navigation.
		virtual void NavigateError(IDispatch *pDisp, BSTR URL, BSTR TargetFrameName, int StatusCode, VARIANT_BOOL * Cancel) = 0;
		//Fires when a new window is to be created.
		virtual void NewWindow(IDispatch ** ppDisp, VARIANT_BOOL * Cancel) = 0;
		//Fires when the IWebBrowser2::Visible property of the object is changed.
		virtual void OnVisible(VARIANT_BOOL Visible) = 0;
		//Fires when a print template has been instantiated.
		virtual void PrintTemplateInstantiation(IDispatch *pDisp) = 0;
		//Fires when a print template has been destroyed.
		virtual void PrintTemplateTeardown(IDispatch *pDisp) = 0;
		//Fired when an event occurs that impacts privacy or when a user 
		//navigates away from a URL that has impacted privacy.
		virtual void PrivacyImpactedStateChange(VARIANT_BOOL PrivacyImpacted) = 0;
		//Fires when the progress of a download operation is updated on the object. 
		virtual void ProgressChange(long Progress, long ProgressMax) = 0;
		//Fires when the IWebBrowser2::PutProperty method of the object changes the value of a property.
		virtual void PropertyChange(BSTR szProperty) = 0;
		//Fires when there is a change in encryption level.
		virtual void SetSecureLockIcon(long SecureLockIcon) = 0;
		//Fires when the status bar text of the object has changed.
		virtual void StatusTextChange(BSTR Text) = 0;
		//Fires when the title of a document in the object becomes available or changes.
		virtual void TitleChange(BSTR Text) = 0;
		//Fires when the window of the object is about to be closed by script.(@IE5.5)
		virtual void WindowClosing(VARIANT_BOOL IsChildWindow, VARIANT_BOOL *Cancel) = 0;
		//Fires when the object changes its height.(@IE5.5)
		virtual void WindowSetHeight(long Height) = 0;
		//Fires when the object changes its left position.(@IE5.5)
		virtual void WindowSetLeft(long Left) = 0;
		//Fires to indicate whether the host window should 
		//allow or disallow resizing of the object.(@IE5.5)
		virtual void WindowSetResizable(VARIANT_BOOL Resizable) = 0;
		//Fires when the object changes its top position.(@IE5.5)
		virtual void WindowSetTop(long Top) = 0;
		//Fires when the object changes its width.(@IE5.5)
		virtual void WindowSetWidth(long Width) = 0;
	};

	class IExternalDispatcher
	{
	public:
		virtual ~IExternalDispatcher(){};
		virtual bool GetIDOfName(const char * name, DISPID * pid) = 0;
		virtual HRESULT Invoke(DISPID dispId, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) = 0;
	};

	enum {
		OPT_ADDRESSBAR	= 0x0001,
		OPT_ENABLEDROP	= 0x0002,
		OPT_RESIZABLE	= 0x0004,
		OPT_THEATERMODE	= 0x0008,
		OPT_SILENT		= 0x0010,
	};

	class IWebWindow
	{
	public:
		virtual ~IWebWindow(){};
		virtual bool OutputPage(const char * url) = 0;
		virtual bool OutputPage(const wchar_t * url) = 0;
		virtual bool OutputText(const char * text) = 0;
		virtual bool OutputText(const wchar_t * text) = 0;
		virtual bool OutputStream(IStream * stream) = 0;
		virtual bool Attach(HWND hwnd, int options = 0) = 0;
		virtual void AdjustWindow(long width, long height) = 0;
		virtual bool LoadingFinished() = 0;
		virtual bool GetHtmlDocument(IHTMLDocument2 ** lplpDocument) = 0;
		virtual bool GetHtmlWindow(IHTMLWindow2 ** lplpWindow) = 0;
		virtual IEventHandler * RegistEventHandler(IEventHandler * handle) = 0;
		virtual IExternalDispatcher * RegistExternalDispatcher(IExternalDispatcher * dispatcher) = 0;
	};


	WEBWINDOWAPI IWebWindow * CreateWebWindow();
	WEBWINDOWAPI void DestroyWebWindow(IWebWindow *);
}



//----------------------------------------------------------
#endif	//ifndef WEBWINDOW_HEADER_WEBWINDOW_H

